package com.huafeng.controller;

import com.huafeng.annotations.Log;
import com.huafeng.model.base.Result;
import com.huafeng.model.entity.SysLoginLog;
import com.huafeng.model.enums.OperationTypeEnum;
import com.huafeng.model.vo.SysLoginLogQueryVo;
import com.huafeng.service.SysLoginLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author 花风
 * @date 2023/8/19 10:24
 * @Description sysLoginLogController
 */
@Api(tags = "登录日志管理")
@RestController
@RequestMapping("admin/system/sysLoginLog")
public class SysLoginLogController {
    @Resource
    private SysLoginLogService sysLoginLogService;

    @Log(model = "登录日志管理",operationType = OperationTypeEnum.GET)
    @ApiOperation("分页条件查询登录日志")
    @GetMapping("page")
    public Result queryLoginLogByPage(SysLoginLogQueryVo sysLoginLogQueryVo){
        return sysLoginLogService.queryLoginLogByPage(sysLoginLogQueryVo);
    }

    @Log(model = "登录日志管理",operationType = OperationTypeEnum.INSERT)
    @ApiOperation("新增登录日志")
    @PostMapping("save")
    public void save(@RequestBody SysLoginLog sysLoginLog){
        sysLoginLogService.recordLoginLog(sysLoginLog.getUsername(),sysLoginLog.getStatus(),sysLoginLog.getIpaddr(),sysLoginLog.getMsg());
    }
}

